package cn.lili.controller.promotion;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.GreenContributionInfo;
import cn.lili.modules.promotion.entity.dos.GreenCount;
import cn.lili.modules.promotion.entity.dos.GreenUnitPrice;
import cn.lili.modules.promotion.service.GreenContributionInfoService;
import cn.lili.modules.promotion.service.GreenCountService;
import cn.lili.modules.promotion.service.GreenUnitPriceService;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiangqian
 * @version 1.0
 * @data 2023/12/19 11:08
 * <p>
 * 运营绿色积分池
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/promotion/green/run")
public class GreenRunController {

    private final GreenContributionInfoService greenContributionInfoService;
    private final GreenUnitPriceService greenUnitPriceService;
    private final GreenCountService greenCountService;

    /**
     * 添加待结算贡献值/绿色积分
     *
     * @param greenContributionInfo 添加数据{@link GreenContributionInfo}
     * @return 返回结果
     */
    @PostMapping("/saveSettle")
    public ResultMessage<Boolean> saveSettle(@RequestBody GreenContributionInfo greenContributionInfo) {
        return ResultUtil.data(greenContributionInfoService.saveSettle(greenContributionInfo));
    }

    /**
     * 添加结算贡献值/绿色积分
     *
     * @param greenContributionInfo 添加数据{@link GreenContributionInfo}
     * @return 返回结果
     */
    @PutMapping("/settle")
    public ResultMessage<Boolean> settle(@RequestBody GreenContributionInfo greenContributionInfo) {
        return ResultUtil.data(greenContributionInfoService.settle(greenContributionInfo.getOrderSn(),greenContributionInfo.getUserId()));
    }

    /**
     * 自动分红
     *
     * @param greenContributionInfo 添加数据{@link GreenContributionInfo}
     * @return 返回结果
     */
    @ApiModelProperty("自动分红")
    @PutMapping("/autoDividend")
    public ResultMessage<Boolean> autoDividend() {
        return ResultUtil.data(greenCountService.autoDividend());
    }

    /**
     * 计算单价
     * @return 返回结果
     */
    @PutMapping("/initGreenUnitPrice")
    public ResultMessage<Boolean> initGreenUnitPrice() {
        return ResultUtil.data(greenUnitPriceService.initGreenUnitPrice());
    }
}
